﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Light.Framework
{
    /// <summary>
    /// 数据库主键字段映射特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Property)]
    public class PrimaryKeyAttribute : Attribute
    {
        public string UnsavedValue { get; set; }

        /// <summary>
        /// 数据库列名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 数据库类型
        /// </summary>
        public DbType Type { get; set; }

        /// <summary>
        /// 长度
        /// </summary>
        public int Size { get; set; }

        /// <summary>
        /// 是否为自增列
        /// </summary>
        public bool IsAutoIncrement { get; set; }

        /// <summary>
        /// 构造函数：列名和属性名一致的时候用
        /// </summary>
        public PrimaryKeyAttribute()
        {
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name">数据库列名</param>
        public PrimaryKeyAttribute(string name)
        {
            Name = name;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name">数据库列名</param>
        /// <param name="IsAutoIncrement">是否为自增列</param>
        public PrimaryKeyAttribute(string name,bool isAutoIncrement)
        {
            Name = name;
            IsAutoIncrement = isAutoIncrement;
        }

        /// <summary>
        /// 构造函数：列名和属性名一致的时候用
        /// </summary>
        /// <param name="IsAutoIncrement">是否为自增列</param>
        public PrimaryKeyAttribute(bool isAutoIncrement)
        {
            IsAutoIncrement = isAutoIncrement;
        }
    }
}
